class Building:
    def __init__(self, name: str):
        self.name = name

    def __repr__(self):
        return f"Building(name={self.name})"


class Course:
    def __init__(self, title: str, building: Building):
        if building is None:
            raise ValueError("Course一定在某个Building中进行")
        self.title = title
        self.building = building

    def __repr__(self):
        return f"Course(title={self.title}, building={self.building.name})"


class College:
    def __init__(self):
        self.buildings = []
        self.courses = []

    def add_building(self, building: Building):
        self.buildings.append(building)

    def add_course(self, course: Course):
        if course.building not in self.buildings:
            raise ValueError(f"Course一定在某个Building中进行: {self.buildings}")
        self.courses.append(course)

    def __repr__(self):
        return (f"College(buildings={self.buildings}, "
                f"courses={self.courses})")


# 示例
if __name__ == "__main__":
    college = College()

    # 添加建筑
    building1 = Building("J楼")
    building2 = Building("W楼")
    college.add_building(building1)
    college.add_building(building2)

    # 添加课程
    course1 = Course("Python", building1)
    course2 = Course("English", building2)

    college.add_course(course1)
    college.add_course(course2)

    print(college)
